//
//  RDeletePopViewController.m
//  Riji
//
//  Created by  on 2022/8/19.
//

#import "RDeletePopViewController.h"
#import "RDeleteCell.h"

@interface RDeletePopViewController ()
@property (strong, nonatomic) IBOutlet UITableView *tablView;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *tableViewH;

@end

@implementation RDeletePopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tablView registerNib:[RDeleteCell nib] forCellReuseIdentifier:[RDeleteCell ID]];
    if (@available(iOS 11.0, *)) {
        self.tablView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}
- (void)setTitles:(NSArray *)titles{
    _titles = titles;
    self.tableViewH.constant = 44 * titles.count;
    [self.tablView reloadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.titles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RDeleteCell *cell = [tableView dequeueReusableCellWithIdentifier:[RDeleteCell ID]];
    cell.content.text = LS(self.titles[indexPath.row]);
    return  cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return  nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self dismissViewControllerAnimated:NO completion:nil];
    if (self.deleteBlock) {
        self.deleteBlock(self.titles[indexPath.row]);
    }
}
@end
